#!/usr/bin/env python3
# coding: utf-8

import numpy as np
import cv2 as cv

file = "/home/liuj/rtsp/234.mp4"
cap = cv.VideoCapture(file)

video_cvt = True
video_type = None
ret, frame = cap.read()

help_str="""
1 正常显示
2 灰度显示
3 边界检测
q 退出
"""

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        print("read video mp4 failed")
        break
    if video_type == 2:
        frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    elif video_type == 3:
        # gray_image = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        # blurred_image = cv.GaussianBlur(gray_image, (5, 5), 0)
        # frame = cv.Canny(blurred_image, threshold1=50, threshold2=150)
        frame = cv.Canny(frame, threshold1=50, threshold2=150)

    cv.imshow("video", frame)
    key = cv.waitKey(40) & 0xFF
    if key == ord("q"):
        break
    elif key == ord("1"):
        video_type = 1
    elif key == ord("2"):
        video_type = 2
    elif key == ord("3"):
        video_type = 3


cap.release()
cv.destroyAllWindows()
